<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  mounted () {
    window.addEventListener('beforeunload', this.handleBeforeUnload)
  },
  methods: {
    // 关闭页面和浏览器触发
    handleBeforeUnload () {
      // 用户关闭页面了
      localStorage.setItem('status', '页面关闭时间：' + new Date().toLocaleString())
    }
  },
  beforeDestroy () {
    window.removeEventListener('beforeunload', this.handleBeforeUnload)
  }
}
</script>
